<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>组件的嵌套</title>
    <script src="js/vue.js"></script>
</head>
<body>
<div id="root">
    <app></app>
</div>
<script>
    Vue.config.productionTip = false;
    // 必须在引入之前创建
    const student = Vue.extend({
        template: `
          <div>
          <h2>学生姓名：{{ studentName }}</h2>
          <h2>学生年龄：{{ age }}</h2>
          </div>
        `,
        data() {
            return {
                studentName: '张三',
                age: 18
            };
        }
    });
    // 创建school组件
    const school = Vue.extend({
        template: `
          <div>
          <h2>学校名称：{{ schoolName }}</h2>
          <h2>学校地址：{{ address }}</h2>
          <!--组件嵌套-->
          <student></student>
          </div>
        `,
        data() {
            return {
                schoolName: '西工大',
                address: '长安校区'
            };
        },
        components: {
            student
        }
    });
    // 创建一个与school平级的组件
    const hello = Vue.extend({
        template: `
          <div>
          <h2>{{ sayHello }}</h2>
          </div>
        `,
        data() {
            return {
                sayHello: '欢迎来学习Vue',
            };
        }
    });

    // app组件最大的领导，管理所有的组件，而vm只需要管理app
    const app = Vue.extend({
        template: `
          <div>
          <hello></hello>
          <school></school>
          </div>
        `,
        components: {
            school,
            hello
        }
    });
    new Vue({
        el: '#root',
        // 2. 注册组件（局部注册）
        components: {
            app
        }
    });
</script>
</body>
</html>